package com.lwb.ztx.news.model;

import com.lwb.ztx.bean.NewsSlideBean;
import com.lwb.ztx.utils.LogUtils;
import com.lwb.ztx.utils.OkHttpUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/28.
 */
public class NewsImageModelImpl implements NewsImageModel {
    private OnImageLoadFinishListener listener;

    public NewsImageModelImpl(OnImageLoadFinishListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadImages(String url) {
        OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {
            @Override
            public void onSuccess(String response) {
                List<NewsSlideBean> beans = NewsJsonUtils.readJsonNewsSlideBeans(response);
                LogUtils.d(beans.toString());
                listener.onSuccess(beans);
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure();
            }
        };
        OkHttpUtils.get(url, loadNewsCallback);
    }

    public interface OnImageLoadFinishListener {
        void onSuccess( List<NewsSlideBean> beans);
        void onFailure();
    }
}
